﻿<?php
include_once("../inc/global.php");
include_once("../inc/common.class.php");
include_once("../inc/parameters.php");

set_time_limit(0);

$str_root = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$str_root.= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' . "\n";

/* 生成论坛的Sitemaps */
$sql		= "select fid from bbs_forums";
$result	= $_MyDB->query($sql);
$bbs_str = "";
while($row = $_MyDB->fetch_array($result))
{
	$url			= "http://www.8caike.com/bbs/forumdisplay.php?fid=" . $row["fid"];
	$lastmod	= date("Y-m-d", time());
	
	$bbs_str.= "	<url>\n";
	$bbs_str.= "		<loc>" . $url . "</loc>\n";
	$bbs_str.= "		<lastmod>".$lastmod."</lastmod>\n";
	$bbs_str.= "		<changefreq>daily</changefreq>\n";
	
	if($row["fid"] == 9){
		$bbs_str.= "		<priority>0.8</priority>\n";
	}else{
		$bbs_str.= "		<priority>0.7</priority>\n";
	}
	$bbs_str.= "	</url>\n";
}

//生成帖子
$sql = "select tid from bbs_threads order by tid desc limit 10000";
$result	= $_MyDB->query($sql);
$lastmod	= date("Y-m-d", time());
while($row = $_MyDB->fetch_array($result))
{
	$url			= "http://www.8caike.com/bbs/viewthread.php?tid=".$row["tid"]."&amp;extra=page%3D1";
	
	$bbs_str.= "	<url>\n";
	$bbs_str.= "		<loc>" . $url . "</loc>\n";
	$bbs_str.= "		<lastmod>".$lastmod."</lastmod>\n";
	$bbs_str.= "		<changefreq>daily</changefreq>\n";
	$bbs_str.= "		<priority>0.6</priority>\n";
	$bbs_str.= "	</url>\n";
}

$bbs_str = $str_root . $bbs_str . "</urlset>";

$filename = "../sitemap_bbs.xml";
make_file($filename, $bbs_str);


function make_file($filename, $str)
{
	/* 生成XML文件 */
	if(!$handle = fopen($filename, 'w')) {
		print "不能打开文件 " . $filename . "<BR>";
		exit;
	}
	
	if (!fwrite($handle, $str)) {
		print "不能写入到文件 " . $filename . "<BR>";
		exit;
	}

	fclose($handle);
	echo "已更新到 " . $filename . "<BR>";
}
	
?>